package jfood.waiter;

import jade.core.behaviours.OneShotBehaviour;
import jade.lang.acl.ACLMessage;
import jade.lang.acl.MessageTemplate;
import jfood.gui.WaiterGui;
import jfood.ontology.query.QueryOntology;

public class WaitForCustomerBehaviour extends OneShotBehaviour {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8985731952062501080L;

	@Override
	public void action() {
		MessageTemplate mt = MessageTemplate.MatchPerformative(ACLMessage.REQUEST);

		ACLMessage msg = myAgent.blockingReceive(mt);
		if (msg != null) {		
			if (msg.getOntology() == QueryOntology.NAME)
			{
				((WaiterAgent)myAgent).gui = new WaiterGui(1, (WaiterAgent)myAgent);
				((WaiterAgent)myAgent).gui.setVisible(true);
				((WaiterAgent)myAgent).unregService();
			}
			else
			{
				ACLMessage reply = msg.createReply();
				reply.setPerformative(ACLMessage.UNKNOWN);
				myAgent.send(reply);
			}
		}
		else
		{
			block();
		}
	}

}
